package edu.bu.met683.TravelDroid;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import android.util.Log;


public class Client implements Runnable {
         
	 String output_string;
	 String outputfilename;
     public Client(String str1 , String str)
     {
    	 output_string = str1;
    	 outputfilename =str;
     }
	 public void run() {
         try {
           InetAddress serverAddr = InetAddress.getByName("10.0.2.2");
           Log.d("TCP", "C: Connecting...");
           Socket socket = new Socket(serverAddr, 4444);
           String message = "Hello from Client android emulator";

               try {
                Log.d("TCP", "C: Sending: '" + message + "'");
                PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
                out.println(outputfilename);
                out.println(output_string);
                out.println("-1");
                Log.d("TCP", "C: Sent.");
                Log.d("TCP", "C: Done.");
               
             } catch(Exception e) {
                 Log.e("TCP", "S: Error", e);

               } finally {
                  socket.close();
                }

         } catch (Exception e) {
              Log.e("TCP", "C: Error", e);
         }
    }
} 